/*
 *  Netzpult - Your desk on the web
 *  Copyright (C) 2011  Ulrich Hilger, http://uhilger.de
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/
 */

package de.uhilger.netzpult.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

import de.uhilger.netzpult.shared.Folder;

/**
 * 
 * @author Copyright (c) Ulrich Hilger, http://uhilger.de
 * @author Published under the terms and conditions of
 * the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a>
 */
public class FolderRenameDialog extends DialogBox {

	private final Folder dlgFolder;
	private int result;
	
	public static final int RESULT_OK = 1;
	public static final int RESULT_CANCEL = 2;
	
	public FolderRenameDialog(Folder folder) {
		this.dlgFolder = folder;
		
		setHTML("Ordner umbenennen");
		
		Grid grid = new Grid(2, 2);
		setWidget(grid);
		grid.setSize("100%", "100%");
		
		Label lblFolderName = new Label("Ordnername:");
		grid.setWidget(0, 0, lblFolderName);
		
		final TextBox textBox = new TextBox();
		textBox.setText(folder.getName());
		grid.setWidget(0, 1, textBox);
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setSpacing(3);
		grid.setWidget(1, 1, horizontalPanel);
		
		Button btnCancel = new Button("Abbrechen", new ClickHandler(){
			public void onClick(ClickEvent event) {
				handleCancelButton();
			}
		});
		horizontalPanel.add(btnCancel);
		
		Button btnOk = new Button("Speichern", new ClickHandler(){
			public void onClick(ClickEvent event) {
				dlgFolder.setName(textBox.getText());
				handleOkButton();
			}
		});
		horizontalPanel.add(btnOk);
		grid.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_RIGHT);
	}

	private void handleCancelButton() {
		result = RESULT_CANCEL;
		hide();
	}
	
	private void handleOkButton() {
		result = RESULT_OK;
		hide();
	}
	
	public Folder getFolder() {
		return dlgFolder;
	}
	
	public int getResult() {
		return result;
	}
}
